<?php

namespace Home\Controller;
use Think\Controller;
header('content-type:text/html;charset=utf-8');
class BaseController extends Controller{
	
	// 重新定义页面显示函数 daviyu
	public function display($templateFile=''){
	    
	    $content = $this->view->fetch($templateFile);
	    $type = I('cookie.userLanguage');
	    if(empty($type)) $type='en';
	    $content = languageReplace($content, $type);
	    
	    $this->view->display('', '', '', $content);
	}
	
	public function _initialize(){
		
		// if ($_GET['auth_code'] != C('auth_code')) {
		// 	if (session('s_authcode') != C('auth_code')) {
		// 		exit('禁止访问，请联系管理员或客服，错误码ERR-'.GetRandStr(50));exit;
		// 	}
		// } else{
		// 	session('s_authcode',$_GET['auth_code']);
		// }



		//检测登录状态
		$userid = session('user');
		if (C('is_weixin') == '1' && is_weixin()) {
			if(CONTROLLER_NAME!='Index'){
				if(empty($userid['id'])){
					$this->redirect('Index/index');
				}
			}
		} else {
			if(CONTROLLER_NAME!='Index' && CONTROLLER_NAME!='Run'){
				if(empty($userid['id'])){
						$this->redirect('Index/login');
				}
			} else if (CONTROLLER_NAME =='Index'){
				if(empty($userid['id'])){
					if (ACTION_NAME =='register'){
					//$this->redirect('Index/register');
					}else if (ACTION_NAME !='index' && ACTION_NAME !='login' ){
						
						$this->redirect('Index/login');
					}
			
				}
				
			}
		}
		
		if (isset($userid['id'])) {
			$userinfo = M('user')->where("id = {$userid['id']}")->find();
		} else {
			$userinfo = array();
		}
		$this->assign('userinfo',$userinfo);
	}
}
?>